package com.techstar.common.converter;

import org.joda.time.DateTime;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.sql.Timestamp;

@Converter(autoApply = true)
public class DateTimeConverter implements AttributeConverter<DateTime, Timestamp> {

	@Override
	public Timestamp convertToDatabaseColumn(DateTime attribute) {
		return null != attribute ? new Timestamp(attribute.getMillis()) : null;
	}
	
	@Override
	public DateTime convertToEntityAttribute(Timestamp dbData) {
		return null != dbData ? new DateTime(dbData.getTime()) : null;
	}
}
